package org.example.controller.sysManage;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.example.model.common.ResponseResult;
import org.example.model.user.dtos.OSContainsNameDto;
import org.example.model.user.dtos.OrganizationStructureDto;
import org.example.model.user.vos.AddOrganizationStructureVo;
import org.example.model.user.vos.SearchOsVo;
import org.example.controller.common.permission.PermissionControl;
import org.example.service.user.OrganizationStructureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 组织架构表现层
 */
@CrossOrigin
@RestController
@RequestMapping("/organization-structure")
@Api(value = "组织架构接口", tags = {"组织架构接口"})
@PermissionControl(Parent = "系统配置", Name = "组织架构", Order = 1)
public class OrganizationStructureController {

    @Autowired
    private OrganizationStructureService organizationStructureService;

    /**
     * 添加一条组织架构信息
     * @param addOrganizationStructureVo 要修改的组织架构信息
     */
    @PostMapping
    @ApiOperation("添加一条组织架构信息")
    @PermissionControl(Parent = "组织架构", Name = "添加", Order = 1)
    public ResponseResult<Boolean> AddOrganizationStructure (@RequestBody AddOrganizationStructureVo addOrganizationStructureVo) {
        return organizationStructureService.InsertOrganizationStructure(addOrganizationStructureVo);
    }

    /**
     * 根据id修改一条组织架构信息
     * @param addOrganizationStructureVo 要修改的组织架构信息
     */
    @PutMapping
    @ApiOperation("根据id修改一条组织架构信息")
    @PermissionControl(Parent = "组织架构", Name = "修改", Order = 3)
    public ResponseResult<Boolean> UpdateOrganizationStructure(@RequestBody AddOrganizationStructureVo addOrganizationStructureVo) {
        return organizationStructureService.UpdateOrganizationStructureById(addOrganizationStructureVo);
    }

    /**
     * 根据id删除一条组织架构信息
     * @param id 组织架构信息id
     */
    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除一条组织架构信息")
    @PermissionControl(Parent = "组织架构", Name = "删除", Order = 2)
    public ResponseResult<Boolean> DeleteOrganizationStructure(@PathVariable int id) {
        return organizationStructureService.DeleteOrganizationStructureById(id);
    }

    /**
     * 获取组织架构树
     */
    @GetMapping("/os-tree")
    @ApiOperation("获取组织架构树")
    @PermissionControl(Parent = "组织架构", Name = "查询", Order = 4)
    public ResponseResult<List<OrganizationStructureDto>>  GetOrganizationStructureList() {
        return organizationStructureService.SelectOrganizationStructureList();
    }

    /**
     * 根据组织架构类型获取组织架构列表
     */
    @GetMapping("/os-list-by-type")
    @ApiOperation("根据组织架构类型获取组织架构列表")
    public ResponseResult<List<OSContainsNameDto>> SelectOrganizationStructureListByType(SearchOsVo searchOsVo) {
        return organizationStructureService.SelectOrganizationStructureListByType(searchOsVo);
    }
}
